<?php
/**
 * 子应用入口
 * @param  array
 * @return [type]
 */
function run_upload_app($uri = array()) {
	header("Content-Type:text/html; charset=utf-8");
	header("Access-Control-Allow-Origin: *");
	require SYSTEM_PATH . "/libs/editormd.uploader.class.php";

	error_reporting(E_ALL & ~E_NOTICE);
	//获取发布时间
	$d = date("Y/m/d/", time());

	$savePath = UPLOAD_ROOT_PATH . $d;
	$saveURL = "/uploads/" . $d;

	//写入文件
	if (!file_exists($savePath)) {
		mkdir($savePath, 0777, true);
	}
	$formats = array(
		'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
	);

	$name = 'editormd-image-file';

	if (isset($_FILES[$name])) {
		$imageUploader = new EditorMdUploader($savePath, $saveURL, $formats['image'], 1); // Ymdhis表示按日期生成文件名，利用date()函数

		$imageUploader->config(array(
			'maxSize' => 1024 * 30, // 允许上传的最大文件大小，以KB为单位，默认值为1024
			'cover' => true, // 是否覆盖同名文件，默认为true
		));

		if ($imageUploader->upload($name)) {
			$imageUploader->message('上传成功！', 1);
		}
	}
}
